// 店铺模型
const { Store } = require('../../../models/store');
// 商品模型
const { Goods } = require('../../../models/good');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

/**
 * @api {Get} /stores/:user_id 查询商家店铺
 * @apiGroup Admin-Stores
 *
 * @apiParam {ObjectId} user_id 商家id
 * 
 * @apiSuccess {ObjectId} _id 店铺id
 * @apiSuccess {ObjectId} store_goods  店铺商品
 * @apiSuccess {String} store_name  店铺名称
 * @apiSuccess {String} store_intro  店铺简介
 * @apiSuccess {Array} store_banner  店铺宣传照
 * @apiSuccess {ObjectId} store_cate  店铺商品分类
 * @apiSuccess {ObjectId} store_belong  店铺所属用户
 * @apiSuccess {Array} address  店铺地址
 * @apiSuccess {String} phone  联系电话
 * @apiSuccess {Array} send_address  发货地址
 * @apiSuccess {String} add_time  添加时间
 */
module.exports = async (req, res) => {
	// 店铺id
	let { user_id } = req.params;
	console.log('46',req.params)
	// 根据_id查询店铺信息
	let stores = await Store.findOne({ store_belong: user_id }).populate({path: 'store_goods', model: Goods});
	// 查询为空返回
	if (!stores) return DataReturn.getData(res, 400, [], '未创建店铺');
	// 响应
	return DataReturn.getData(res, 200, stores, '查询店铺信息成功')

}
